//
//  TodayDetailController.swift
//  appstore
//
//  Created by llbt-sk on 2019/11/5.
//  Copyright © 2019 Roy. All rights reserved.
//

import UIKit

class TodayDetailController: BaseViewController,UITableViewDataSource,UITableViewDelegate {

    var headImage:String!
    var content:String!
    
    let DetailTableViewCellIdentifier = "DetailTableViewCellIdentifier"
    
    lazy var detailTableView = UITableView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.initView()
    }
    
    func initView() -> Void {
        detailTableView = UITableView(frame: CGRect.zero, style: .plain)
        detailTableView.dataSource = self
        detailTableView.delegate = self
        detailTableView.separatorStyle = .none
        detailTableView.estimatedRowHeight = 10.0
        detailTableView.rowHeight = UITableView.automaticDimension
        self.view.addSubview(detailTableView)
        detailTableView.snp.makeConstraints { (make) in
            make.left.top.right.bottom.equalTo(self.view)
        }
        detailTableView.register(DetailCell.self, forCellReuseIdentifier: DetailTableViewCellIdentifier)
        
        let tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: ScreenWidth, height: 500.0))
        detailTableView.tableHeaderView = tableHeaderView
        let headImageView = UIImageView()
        headImageView.image = UIImage(named: headImage)
        tableHeaderView.addSubview(headImageView)
        headImageView.snp.makeConstraints { (make) in
            make.left.right.top.bottom.equalTo(0.0)
        }
        
        let closeButton = UIButton(type: .custom)
        closeButton.setImage(UIImage(named: "close_button"), for: .normal)
        closeButton.addTarget(self, action: #selector(backClickAction), for: .touchUpInside)
        self.view.addSubview(closeButton)
        closeButton.snp.makeConstraints { (make) in
            make.right.equalTo(-20.0)
            make.top.equalTo(40.0)
            make.width.height.equalTo(30.0)
        }
            
    }
    
    // UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: DetailTableViewCellIdentifier) as! DetailCell
        cell.contentLabel.text = content
        return cell
    }
    
    @objc func backClickAction() -> Void {
        self.navigationController?.popViewController(animated: true)
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
